package com.github.caijh.mall.filter;

import com.github.caijh.mall.handler.RouterPrefixHandler;

public class ResponseRouter {

    private final RouterPrefixHandler prefixHandler;

    public ResponseRouter(RouterPrefixHandler handler) {
        this.prefixHandler = handler;
    }

    public String filter(String data, String path) {
        if (!path.contains("api/admin/") && !path.contains("api/front/")) {
            return data;
        }

        if (data.contains("image/") && !data.contains("data:image/png;base64")) {
            data = prefixHandler.prefixImage(data);
        }

        if (data.contains("file/")) {
            data = prefixHandler.prefixFile(data);
        }

        return data;
    }

}
